package com.lanyou.cook.service.vo;

import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Date;

import org.apache.commons.io.output.ByteArrayOutputStream;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.gson.GsonBuilder;
import com.lanyou.cook.common.Constants;
import com.lanyou.cook.common.DefaultDateJsonSerializer;

public class InterfaceExecutionParam {

	private String fieldName;
	private String fieldSystemId;
	private String fieldSystemName;
	private String systemInterfaceId;
	private String systemInterfaceName;
	private long kettleJobId;
	private String interfaceScheduleId;
	private String interfaceScheduleName;
	private boolean isManual;
	private Date scheduleTime;
	private int overTimes;

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFieldSystemId() {
		return fieldSystemId;
	}

	public void setFieldSystemId(String fieldSystemId) {
		this.fieldSystemId = fieldSystemId;
	}

	public String getFieldSystemName() {
		return fieldSystemName;
	}

	public void setFieldSystemName(String fieldSystemName) {
		this.fieldSystemName = fieldSystemName;
	}

	public String getSystemInterfaceId() {
		return systemInterfaceId;
	}

	public void setSystemInterfaceId(String systemInterfaceId) {
		this.systemInterfaceId = systemInterfaceId;
	}

	public String getSystemInterfaceName() {
		return systemInterfaceName;
	}

	public void setSystemInterfaceName(String systemInterfaceName) {
		this.systemInterfaceName = systemInterfaceName;
	}

	public long getKettleJobId() {
		return kettleJobId;
	}

	public void setKettleJobId(long kettleJobId) {
		this.kettleJobId = kettleJobId;
	}

	public String getInterfaceScheduleId() {
		return interfaceScheduleId;
	}

	public void setInterfaceScheduleId(String interfaceScheduleId) {
		this.interfaceScheduleId = interfaceScheduleId;
	}

	public String getInterfaceScheduleName() {
		return interfaceScheduleName;
	}

	public void setInterfaceScheduleName(String interfaceScheduleName) {
		this.interfaceScheduleName = interfaceScheduleName;
	}

	public boolean getIsManual() {
		return isManual;
	}

	public void setIsManual(boolean isManual) {
		this.isManual = isManual;
	}
	
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	public Date getScheduleTime() {
		return scheduleTime;
	}

	public void setScheduleTime(Date scheduleTime) {
		this.scheduleTime = scheduleTime;
	}
	
	private static GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat(Constants.DATETIME_PATTERN_2);

	public byte[] serialize() {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			try(OutputStreamWriter writer = new OutputStreamWriter(os, Constants.DEFAULT_CHARSET)) {
				gsonBuilder.create().toJson(this, writer);
				writer.flush();
			}
		} catch (Exception e) {
		}
		return os.toByteArray();
	}
	
	public static InterfaceExecutionParam deserialize(byte[] bytes) {
		return gsonBuilder.create().fromJson(
				new InputStreamReader(new ByteArrayInputStream(bytes), Constants.DEFAULT_CHARSET),
				InterfaceExecutionParam.class);
	}

	public int getOverTimes() {
		return overTimes;
	}

	public void setOverTimes(int overTimes) {
		this.overTimes = overTimes;
	}
	
	

}
